<?php
$conn = mysqli_connect('localhost' , 'root' , 'weicedbmojito160824','weixin_didao_wxapp');
$query = "Set Names 'utf8mb4'";
mysqli_query($conn,$query);

if(isset($_GET['partyId']) && isset($_GET['openid']) && $_GET['jyj']==='jyj') {
    $openid = $_GET['openid'];
    $partyId = $_GET['partyId'];
    $query = "SELECT `openid`,`location`,`name`,`max_member`,`description`,`begin_time`,`begin_time_unix`,`status` FROM didao_wxapp_party WHERE `id` = $partyId LIMIT 1";
    $result = mysqli_query($conn,$query);
    $row = mysqli_fetch_assoc($result);
    $location = json_decode(trim($row['location'],'\"'),true);
    if($_GET['openid'] === $row['openid']){
        $isOrganiser = 1;
    }else{
        $isOrganiser = 0;
    }
    //$row['openid']是发起人的openid
    /**
     * 查有哪些人参加，做成一个数组
     */
    $attender = array();
    $attenderNum = 0;
    $isAttender = 0;
    $query = "SELECT a.`attender_num`,a.`description`,a.`openid`,b.`nick_name`,b.`avatar`
              FROM didao_wxapp_party_attender a 
              LEFT JOIN didao_wxapp_users b
              ON a.openid = b.openid 
              WHERE a.`party_id` = $partyId AND a.cancel_flag = 1";
    $result = mysqli_query($conn,$query);
    while($attender_row = mysqli_fetch_assoc($result)){
        $attender[] = array(
            'attender_num' => $attender_row['attender_num'],
            'description' => $attender_row['description'] == null?'':$attender_row['description'],
            'nickName' => $attender_row['nick_name'],
            'avatar' => $attender_row['avatar'],
            'isOrganiser' => $row['openid'] == $attender_row['openid']?'1':'0'
        );
        if($openid == $attender_row['openid']){
            $isAttender = 1;
        }
        $attenderNum = $attenderNum+$attender_row['attender_num'];
    }

    echo json_encode(array(
        'locationName' => $location['name'],
        'locationAddress' => $location['address'],
        'latitude' => $location['latitude'],
        'longitude' => $location['longitude'],
        'title' => $row['name'],
        'description' => $row['description'],
        'beginTime' => $row['begin_time'],
        'beginTimeUnix' => $row['begin_time_unix'],
        'status' => $row['status'] && ($row['begin_time_unix'] > time()),
        'isOrganiser' => $isOrganiser,
        'isAttender' => $isAttender,
        'attender' => $attender,
        'attenderNum' => $attenderNum,
        'maxMember' => $row['max_member']
    ),JSON_UNESCAPED_UNICODE);

}
/**
 * Created by PhpStorm.
 * User: a7849
 * Date: 2017/7/17
 * Time: 10:34
 */